/**
 * Created by 121 on 2016/4/08.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'template',
    'collection',
    'model',
    'dialog',
    'calendar',
    'highCharts'
], function ($, common, ready, template, Collection, Model, dialog, calendar, highCharts) {
    var id = getUrlPath(4);
    var index = function () {
        this.init();
    };
    index.prototype = {
        init: function () {
            this.event();
            //this.fetch();
        },
        event: function () {
            var _this = this;
            var success = function (status) {
                $.ajax({
                    url: _global.url.api + 'site/data/interview',
                    type: 'get',
                    data: {status: status,id:id},
                    success: function (res) {
                        var data = res.data;
                        console.log(res.data['time']);
                        $("#pv").html('&nbsp' + data['t_pv']);
                        $("#pvs").html('&nbsp' + data['y_pv']);
                        $("#uv").html('&nbsp' + data['t_uv']);
                        $("#uvs").html('&nbsp' + data['y_uv']);
                        $('#high_charts').highcharts({
                            chart: {
                                zoomType: 'xy'
                            },
                            title: {
                                text: ''
                            },
                            xAxis: [{
                                categories: data['time']
                            }
                            ],
                            yAxis: [{
                                floor: 0,
                                labels: {
                                    format: '{value}',
                                    style: {
                                        color: '#89A54E'
                                    }

                                },
                                title: {
                                    text: '',
                                    style: {
                                        color: '#89A54E'
                                    }
                                },
                            }],
                            legend: {
                                layout: 'vertical',
                                verticalAlign: 'middle',
                                align: 'right',
                                backgroundColor: '#FFFFFF'
                            },
                            series: [{
                                name: '今日PV',
                                type: 'spline',
                                data: res.data['pv'],
                                tooltip: {
                                    valueSuffix: ' 次'
                                }

                            }, {
                                name: '今日UV',
                                type: 'spline',
                                data: res.data['uv'],
                                tooltip: {
                                    valueSuffix: '次'
                                }
                            },{
                                name: '昨日PV',
                                type: 'spline',
                                data: res.data['pvs'],
                                tooltip: {
                                    valueSuffix: '次'
                                }
                            },{
                                name: '昨日UV',
                                type: 'spline',
                                data: res.data['uvs'],
                                tooltip: {
                                    valueSuffix: '次'
                                }
                            }]
                        });
                    }
                });
            }

            success();
            $('#btn-success-status').find('a').on('click', function (e) {
                $(this).siblings().removeClass('active');
                e.preventDefault();
                var status = $(e.target).attr('rel');
                success(status);
            });
        }
    };
    new index();
});